package web3.web;

import org.apache.commons.beanutils.BeanUtils;
import web3.ServiceDemo.ServiceDemo;
import web3.user.user1;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Map;

public class Servlet extends javax.servlet.http.HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
//1解析中文乱码
        request.setCharacterEncoding("utf-8");
        //2 处理页面数据
            //处理全部页面数据
        Map<String,String[]> map = request.getParameterMap();
        //创建serviceDemo对象
        ServiceDemo serviceDemo=new ServiceDemo();
        //创建user1对象
        user1 user1=new user1();
         //调用BeanUntils里面的pouplate的方法将map和对象传递过去
            System.out.println(user1);
           BeanUtils.populate(user1,map);
            System.out.println(user1);
            Integer login = serviceDemo.login(user1);
            if (login>0){
                response.setContentType("text/html;charset=utf-8");
                response.getWriter().println("恭喜你登录成功");
            }else{
                response.getWriter().println("恭喜你登陆失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
       doPost(request,response);
    }
}
